﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using fivescomplement.Models;

namespace fivescomplement.Controllers
{
    public class ReportController : Controller
    {
        //
        // GET: /Report/

        public ActionResult Index()
        {
            String authUser2 = User.Identity.Name;
            try
            {
                if (isUserAuth() > 0)
                {
                    using (var database = new C335263_teacherharvestEntities())
                    {
                        var InstitutionData = database.GetInstitutionResults(Session["Reference"].ToString());
                        return View(InstitutionData.ToList());
                    }
                }
                else
                {
                    return RedirectToAction("LogOn", "Account");
                }

            }
            catch
            {
                return RedirectToAction("LogOn", "Account");
            }
            return View();
        }


        public ActionResult Course(string id)
        {
            using (var database = new C335263_teacherharvestEntities())
            {
                var Facultyuser = database.GetCourseResults(id);

                return View(Facultyuser.ToList());
            }

        }

        public int isUserAuth()
        {
            int returnvalue = -1;
            String authUser2 = User.Identity.Name;
            if (authUser2.Equals("") || (Session["Reference"]).ToString().Equals(""))
            {
            }
            else
            {
                returnvalue = 1;
            }
            return returnvalue;
        }



        public ActionResult Instructor(string id)
        {
            string[] temp = id.Split(new Char[] {' '});
            string instructorsFirstName = temp[0];
            string instructorsLastName = temp[1];
                  
            using (var database = new C335263_teacherharvestEntities())
            {
                var instructorcourses = database.GetInstructorsResults(instructorsFirstName, instructorsLastName);
                return View(instructorcourses.ToList());
            }
            
        }

        public ActionResult Report()
        {
            return View();
        }


    }
}
